package com.mimosa.common.system.role;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mimosa.common.system.user.TUserDao;
/**
 * 用户角色关联信息的业务类
 *
 * @filename UserRoleService.java
 * @author ggeagle
 * @date 2013-7-17 下午4:01:01
 */
@Service
@Transactional
public class UserRoleService {

	@Autowired
	private TUserRoleDao userRoleDao;
	
	@Resource
	private TUserDao userDao;

	/**
	 * 根据角色id删除角色用户表中的所有对象
	 * 
	 * @param roleId
	 */
	public void delTUserRoleByRoleId(String roleId, String[] userIds) {
		userRoleDao.deleteUserFromRole(roleId, userIds);
	}

	/**
	 * 建立人到角色之间的关联
	 * 
	 * @param userId
	 * @param roleids
	 */
	public void saveUser2Role(String roleId, String[] userIds) {
		this.userRoleDao.saveUser2Role(roleId, userIds);
	}

	/**
	 * g根据用户id获取所对应的角色
	 * 
	 * @param uid
	 *            用户id
	 * @return
	 */
	public List<TUserRole> getRoleListByUid(String uid) {
		return this.userRoleDao
				.find("from TUserRole u where u.userId = ?", uid);
	}
}